interface DataTreeProps {
 [key:string]:any;
}

export function toTree(data:DataTreeProps[], pid:string,pidKey='pid',keyKey='id', valueKey='id',titleKey='name') {
    let tree = [];
    let temp;
    for (var i in data) {
        let obj = data[i];
        if (obj[pidKey] == pid) {
            obj.key = obj[keyKey] + '';
            obj.value = obj[valueKey] + '';
            obj.title = obj[titleKey];
            temp = toTree(data, data[i][keyKey], pidKey,keyKey,valueKey,titleKey);
            if (temp.length > 0) {
                obj.children = temp;
            }
            tree.push(obj);
        }
    }
    return tree;
};
